<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>校园二手交易信息管理平台</title>
<%@ include file="./common_header.jsp" %>
<style type="text/css">
*{margin:0; padding:0;}
ul{list-style-type:none; zoom:1;}
ul li{float:center; margin:10px; _display:inline; border:0px solid #CCC;}
ul li a img{width:48px; height:48px; border:0;display:block;margin:0px auto; vertical-align: middle;text-align:center;}
ul li a.wenzi{line-height:20px; color:#666; display:block; text-align:center;}
ul li a:hover{color:#F00;}
ul li a:link{text-decoration: none;}
.tabsMenu .split{line-height:1px;color:black;display:block;}
</style>
<script type="text/javascript">
	//动态生成操作菜单
	$(document).ready(function() {
		$.ajax({
			url:'${ctx}/manage/showMenu',
			type:'post',
			async:false,
			dataType:'json',
			success:function(data){
				if(data.success==0)
				{
				    var pid=0;
				    var content="";
				    var title="";
				    var imgCls="";
					$.each(data.rows,function(i,item){
					    var content="";
					    if(item.children != null)
					    {
					        $.each(item.children,function(i,subItem){
                                content = content + "<li><a href=\"javascript:addTab(\'"+subItem.name+"\',\'"+subItem.url+"\')\"><img src=\"${ctx}/images/icon/"+subItem.img+"\" width=\"32\" /></a><a class=\"wenzi\" href=\"javascript:addTab(\'"+subItem.name+"\',\'"+subItem.url+"\')\">"+subItem.name+"</a></li>";
					        });
					    }
					    $('#nav_menu').accordion('add', {
                            title: "&nbsp;&nbsp;"+item.name,
                            content: '<div style="padding:0px;overflow:hidden"><ul id="ulSubMenu'+item.id+'">'+content+'</ul></div>',
                            selected: item.name='系统管理',
                            iconCls: item.img
                        }); 
					});
				}
				else
				{
					showErrMsg(data);
					window.parent.location.href="${ctx}/manage"
				}
			}
		});
	});
	function logout(flag)
	{
	    var msg;
	    if(flag)
	    {
	        msg = "你是否要退出系统？";
	    }
	    else
	    {
	        msg = "你是否要重新登录系统？";
	    }
	    $.messager.confirm("退出",msg,function(yesOrNo){
	        if(yesOrNo)
	        {
	            $.ajax("${ctx}/manage/logout",{
	                error:function(){
	                    $.messager.alert("提示","资源访问错误！");
	                },
	                success:function(json){
						window.parent.location.href="${ctx}/manage"
	                }
	            });
	        }
	    });
	}
	function addTab(title,url){
          	if ($('#centerTabs').tabs('exists', title))
          	{
              	var currtab = $('#centerTabs').tabs('getSelected');
              	var tab = $("#centerTabs").tabs("getTab", title);
              	if (currtab == tab) {
                  	var url=$(currtab.panel('options').content).attr('src');
                  	refreshTab(tab, url);
              	}
              	else {
                  	var tab = $("#centerTabs").tabs("select", title);
                  	var currtab = $('#centerTabs').tabs('getSelected');
                  	var url = $(currtab.panel('options').content).attr('src');
                  	refreshTab(tab, url);
              	}
          	}
          	else {
		     var content = '<iframe scrolling="auto" frameborder="0" src="'+url+'" style="width:100%;height:100%;"></iframe>';
              	$('#centerTabs').tabs('add',
                  {
                      title: title,
                      content: content,
                      closable: true
                  });
          	}
      	}
		function refreshTab(obj,url)
		{
		     var refresh_tab = obj;
		     if (refresh_tab && refresh_tab.find('iframe').length > 0)
		        {
		           var _refresh_ifram = refresh_tab.find('iframe')[0];
		           _refresh_ifram.contentWindow.location.href = url;
		        } 
		}
		$(function () {
		    //绑定tabs的右键菜单
		    $("#centerTabs").tabs({
		        onContextMenu : function (e, title) {
		            e.preventDefault();
		            $('#tabsMenu').menu('show', {
		                left : e.pageX,
		                top : e.pageY
		            }).data("tabTitle", title);
		        }
		    });
		    //实例化menu的onClick事件
		    $("#tabsMenu").menu({
		        onClick : function (item) {
		        	if(item.name == 'refresh')
		        	{
		        		var refresh_tab = $('#centerTabs').tabs('getSelected');
		        		if (refresh_tab && refresh_tab.find('iframe').length > 0)
				        {
				           var _refresh_ifram = refresh_tab.find('iframe')[0];
				           _refresh_ifram.contentWindow.location.reload();
				        } 
		        	}
		        	else
		        	{
			            CloseTab(this, item.name);
		        	}
		        }
		    });
		    //几个关闭事件的实现
		    function CloseTab(menu, type) {
		        var curTabTitle = $(menu).data("tabTitle");
		        var tabs = $("#centerTabs");
		        
		        if (type === "close") {
		            tabs.tabs("close", curTabTitle);
		            return;
		        }
		        var allTabs = tabs.tabs("tabs");
		        var closeTabsTitle = [];
		        $.each(allTabs, function () {
		            var opt = $(this).panel("options");
		            if (opt.closable && opt.title != curTabTitle && type === "Other") {
		                closeTabsTitle.push(opt.title);
		            } else if (opt.closable && type === "All") {
		                closeTabsTitle.push(opt.title);
		            }
		        });
		        for (var i = 0; i < closeTabsTitle.length; i++) {
		            tabs.tabs("close", closeTabsTitle[i]);
		        }
		    }
		});
	function changePwd()
	{
        var params = {
                winId:'win_change_pwd',
                title:'修改密码',
                width:330,
                height:235,
                showUrl:'${ctx}/manage/changePwd',
                refresh_fun:function(){
                    top.Ext.Msg.alert("提示","密码修改成功，下次登录请使用新密码！");
                }
                
        };
        open_fun(params);
	    
	}
	function show(){
		var date = new Date(); //日期对象
		var now = "";
		now = date.getFullYear()+"/"; //读英文就行了
		now = now + (date.getMonth()+1)+"/"; //取月的时候取的是当前月-1如果想取当前月+1就可以了
		now = now + date.getDate()+" &nbsp;&nbsp;";
		now = now + date.getHours()+":";
		now = now + date.getMinutes()+":";
		now = now + date.getSeconds()+"&nbsp";
		document.getElementById("nowDiv").innerHTML = now; //div的html是now这个字符串
		setTimeout("show()",1000); //设置过1000毫秒就是1秒，调用show方法
		}
	</script>
</head>
<body class="easyui-layout" onload="show()">
	<!-- 上部   start -->
	<div data-options="region:'north',border:false" style="height:130px;no-repeat;padding:1px;background:#FFDAB9"><div style="margin-left: 40;"><img src="${ctx }/images/shouye.jpg" width="950" height="135" /></div>
		<div style="position: absolute; right: 0px; bottom: 0px; ">
			<a href="javascript:void(0);" class="easyui-menubutton" menu="#layout_north_kzmbMenu" iconCls="icon-more">更换主题</a><a href="javascript:void(0);" class="easyui-menubutton" menu="#layout_north_zxMenu" iconCls="icon-back">注销</a>
			<div id="nowDiv" align="center" ></div>
		</div>
		<div  style="width: 100px; display: none;">
			<div>
				<div id="layout_north_kzmbMenu" style="width: 100px;">
					<div onclick="javascript:changeTheme('default')">默认</div>  
            		<div onclick="javascript:changeTheme('gray')">灰色（gray）</div>  
         			<div onclick="javascript:changeTheme('black')">黑色（black）</div>
         			<div onclick="javascript:changeTheme('green')">绿色（black）</div>     
				</div>
			</div>
			 
		</div>
		<div id="layout_north_zxMenu" style="width: 100px; display: none;">
			<div onclick="changePwd();">修改密码</div>
			<div onclick="logout();">重新登录</div>
			<div onclick="logout(true);">注销</div>
			
		</div>
	</div>
	<!-- 上部   end -->
	<!-- 导航  start -->
	<div data-options="region:'west',split:false,title:'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;菜单列表'" style="width:165px;padding:0px;overflow:hidden;background:#66CDAA">
		<div id="nav_menu" class="easyui-accordion" fit="true" border="false" style="">
		</div>
	</div>
	<!-- 导航   end -->
	<!-- 中间   start -->	
	<div data-options="region:'center',title:'当前用户【${user.userName }】'"  > 
		<div id="centerTabs" class="easyui-tabs" fit="true">  
		 	<div title="首页" style="">
		 	<iframe scrolling="auto" frameborder="0" src="/manage/sysMenus/index" style="width:100%;height:100%;"></iframe>  
    		</div>  
		</div>
	</div>		
	<div id="tabsMenu" class="easyui-menu" style="width:120px;">
	    <div name="refresh">刷新</div>   
	    <div name="close">关闭</div>  
	    <div name="Other">关闭其他</div>  
	    <div name="All">关闭所有</div>
	  </div>  
	<!-- 中间   end -->	
	<!-- 底部   start -->
	<div data-options="region:'south',border:false" style="height:25px;padding:1px;">
	
	</div>
	<!-- 底部   end -->
</body>
</html>